// pages/custom/makelist/makelist.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrolltop: 0,
    offset:0,
    list:[],
    hasMore:false,
    blankshow:false,
    stateArr:[],
    listOffset:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollhgt: res.windowHeight
        });
      },
    });
    this.loadList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  loadList: function () {
    this.loadCustomList(0);
  },
  loadCustomList: function (offset) {
    var url = app.globalData.webUrl + '/index.php/api/Custom/getUserCustom';
    var params = {
      page: offset
    }
    app.loadDataFromServer(url, this.CoutomCallBack, params);
  },
  CoutomCallBack: function (res) {
    // console.log(res);
    wx.hideToast();
    var dataArr = res.result.arr;
    var stateArr = res.result.sarr;
    this.setData({
      stateArr: stateArr
    });

    for(var i =0;i<dataArr.length;i++){
      dataArr[i].stateDesc = stateArr[dataArr[i].state];
      dataArr[i].addtime = app.formatDateTime(dataArr[i].addtime)
    }

    if (dataArr.length <= 0) {
      if (this.data.listOffset == 0) {
        this.setData({
          blankshow: true
        });
      }
      else {
        this.setData({
          hasMore: false
        });
      }
      return;
    }
    else if (dataArr.length <= 10 && dataArr.length > 0) {
      var addlist = this.data.list.concat(dataArr);
      console.log('addlist=' + addlist.length);
      this.setData({
        list: addlist,
        hasMore:true
      });
    }
  },
  showDetail:function(e){
    var tuid = e.currentTarget.dataset.tuid; 
    wx.navigateTo({
      url: '../detail/detail?tuid=' + tuid,
    });
  },
  loadMoreCustom:function(){
    console.log('aabbcc');
    //加载更多的
    if (this.data.hasMore == false) {
      return;
    }
    this.data.listOffset++;
    app.appShowLoading(30000);
    this.loadCustomList(this.data.listOffset);
  }
})